package com.xy.controller;

import com.xy.service.IFileHandlerService;
import com.xy.utils.ConfigUtil;
import com.xy.utils.Response;
import com.xy.utils.ResponseFactory;
import com.xy.vo.FileVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/upload")
@Tag(name = "文件上传", description = "fileUpload")
public class FileHandlerController {
    private static final String UPLOAD_DIR = ConfigUtil.readProperty("file_path");

    private final IFileHandlerService fileUploadService;
    @Autowired
    public FileHandlerController(IFileHandlerService fileUploadService) {
        this.fileUploadService = fileUploadService;
    }

    @PostMapping("/uploadFile")
    public Response<FileVO> handleFileUpload(
            @RequestParam("file") MultipartFile file) {
        return ResponseFactory.okResponse(fileUploadService.importFile(file));
    }

    @PostMapping("/uploadFiles")
    public Response<List<FileVO>> handleFilesUpload(
            @RequestParam("files") List<MultipartFile> files) {
        return ResponseFactory.okResponse(fileUploadService.importFiles(files));
    }

}
